package com.zut.domain.sevice.impl;

import com.zut.auth.infra.entity.AuthRole;
import com.zut.auth.infra.entity.AuthRolePermission;
import com.zut.auth.infra.service.AuthRolePermissionService;
import com.zut.auth.infra.service.AuthRoleService;
import com.zut.common.enums.IsDeletedFlagEnum;
import com.zut.common.enums.StatusFlagEnum;
import com.zut.domain.convert.AuthRoleBOConverter;
import com.zut.domain.convert.AuthRolePermissionBOConverter;
import com.zut.domain.entity.AuthRoleBO;
import com.zut.domain.entity.AuthRolePermissionBO;
import com.zut.domain.sevice.AuthRoleDomainService;
import com.zut.domain.sevice.AuthRolePermissionDomainService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {


    @Resource
    private AuthRolePermissionService authRolePermissionService;

    //添加角色权限关联
    @SneakyThrows
    @Override
    public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
        List<AuthRolePermission> authRolePermissionList =new ArrayList<>();

        authRolePermissionBO.getPermissionIdList().forEach(permissionId ->{
            AuthRolePermission authRolePermission =new AuthRolePermission();
            authRolePermission.setPermissionId(permissionId);
            authRolePermission.setRoleId(authRolePermissionBO.getRoleId());
            authRolePermission.setIsDelete(IsDeletedFlagEnum.UN_DELETED.getCode());
            authRolePermissionList.add(authRolePermission);
        });

        int insert =authRolePermissionService.inertBath(authRolePermissionList);
        return insert>0;
    }


}
